package com.stone.business.jc.action;

/**
 * <pre>
 * 考试
 * @author 
 * </pre>
 */

import java.util.ArrayList;

import java.util.List;

import com.stone.business.jc.pojo.TCxxc;
import com.stone.business.jc.pojo.TCxxcRy;

import com.stone.business.jc.service.JcCommonService;

import frm.ssh.action.BaseAction;
import frm.ssh.exception.AppException;

public class CxxcAction extends BaseAction {
	
	private static final long serialVersionUID = -4647594073681054487L;

	private JcCommonService myService;
	
	private TCxxc entity;
	
	private String id;
	
	private List<TCxxcRy> cxxcryList;
	
	/**
	 * 进入详细页面
	 * @return
	 * @throws AppException
	 */
	public String initDetail() throws AppException {
		
		// 修改进入
		if (!"0".equals(id)) {
			
			this.entity = (TCxxc)myService.findById(Long.parseLong(id), TCxxc.class.getName());
			cxxcryList = myService.findListByHql(" from TCxxcRy where ksid = '" + id + "' order by userid desc");

			// 新建进入
		} else {
			
			this.entity = new TCxxc();
			this.entity.setId(Long.parseLong("0"));
			// 0 培训 1考试
			this.entity.setState(super.getSearchBean().getCon1());
			cxxcryList = new ArrayList<TCxxcRy>();

		}

		return SUCCESS;
	}
	
	/**
	 * 保存
	 * @return
	 * @throws AppException
	 */
	public String save() throws AppException {
		
		myService.saveCxxc(entity, this.cxxcryList);
		cxxcryList = myService.findListByHql(" from TCxxcRy where ksid = '" + entity.getId() + "' order by userid desc");
		super.setInfo("保存成功");
		
		return SUCCESS;
	}
	
	/**
	 * 删除
	 * @return
	 * @throws AppException
	 */
	public String delete() throws AppException {
		
		myService.deleteCxxc(id);
		
		return "DEL-SUCCESS";
		
	}
	
	public void deleteCxxcRy() throws Exception {
		myService.doDelAll(id, "TCxxcRy");
        super.getResponse().getWriter().print("{msg:'删除成功'}");
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setMyService(JcCommonService myService) {
		this.myService = myService;
	}

	public TCxxc getEntity() {
		return entity;
	}

	public void setEntity(TCxxc entity) {
		this.entity = entity;
	}

	public List<TCxxcRy> getCxxcryList() {
		return cxxcryList;
	}

	public void setCxxcryList(List<TCxxcRy> cxxcryList) {
		this.cxxcryList = cxxcryList;
	}
	
	

}
